package com.syj.collect.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.syj.collect.app.R;
import com.syj.collect.entry.MyPhone;
import com.syj.collect.model.MyPhontoActivity;

import java.util.ArrayList;
import java.util.List;

public  class MyPictureAdapter extends RecyclerView.Adapter<MyPictureAdapter.PictureViewHoder> {
    private MyPhontoActivity context;
    private List<MyPhone.DataDTO.ListDTO> list;
    private PictureItemAdapter adapter;
    public MyPictureAdapter(MyPhontoActivity context) {
        this.context=context;
        list=new ArrayList<>();

    }

    @NonNull
    @Override
    public MyPictureAdapter.PictureViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_picture,parent,false);
        return new PictureViewHoder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyPictureAdapter.PictureViewHoder holder, int position) {
        holder.address_tv.setText(list.get(position).getAddress()+"");

         adapter=new PictureItemAdapter(context,list.get(position).getUrls());//具体参数还需要在传递
        holder.pic_rcl.setLayoutManager(new GridLayoutManager(context,3));
        holder.pic_rcl.setAdapter(adapter);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addList(List<MyPhone.DataDTO.ListDTO> data, int page) {
        if (page==1){
            list.clear();
        }
        list.addAll(data);
        notifyDataSetChanged();
    }

    public class PictureViewHoder extends RecyclerView.ViewHolder {
        TextView address_tv;
        RecyclerView pic_rcl;
        public PictureViewHoder(@NonNull View itemView) {
            super(itemView);
            address_tv=itemView.findViewById(R.id.address_tv);
            pic_rcl=itemView.findViewById(R.id.pic_rcl);
        }
    }
}
